<template>
  <div class="risk-of">
    <tittle-one>每日树脂消耗</tittle-one>
    <div>(未设置树脂数据或未使用树脂，先取消)</div>
    <my-num title="秘境(浓缩) 40" @bk="bk1" />
    <my-num title="世界BOSS" @bk="bk2" />
    <my-num title="通用 40" @bk="bk3" />
    <my-num title="通用 20" @bk="bk4" />
    <div v-show="show">
      <hr>
    <my-num title="周本(半价 30)" :limit="3" @bk="bk5" />
    <my-num title="周本 60" @bk="bk6" />
      <my-num title="地脉(浓缩) 40" @bk="bk7" />
      <my-num title="秘境 20" @bk="bk8" />
      <my-num title="地脉 20" @bk="bk9" />
    </div>
    <el-button @click="chg">{{btn[show]}}</el-button>
    <div style="margin: 10px">
      <el-button type="warning" @click="doNot">取消</el-button>
      <el-button type="success" @click="doOk">提交</el-button>
    </div>
    <tittle-one>当前选择</tittle-one>
    <div v-if="okrisk">
      <div v-for="k in keys">
        <div v-if="form1[k].v!==0" style="display: flex; justify-content: space-evenly">
          <div>{{form1[k].nm}}次</div>
          <div>{{form1[k].v}}次</div>
        </div>
      </div>
    </div>
    <div v-else>
      无
    </div>
  </div>
</template>

<script>
import MyNum from "../temp/MyNum";
import TittleOne from "../temp/TittleOne";
import {riskForm, riskChk, riskSz} from "../../data/com";
import { getCookie, setCookie, delCookie, goto} from  '../../util/request'

export default {
  name: "RiskOf",
  components: {TittleOne, MyNum},
  data() {
    return {
      show: 0,
      okrisk: false,
      btn: ['更多', '收起'],
      form: riskForm,
      form1: {},
      keys: []
    }
  },
  methods: {
    chg() {
      this.show = (this.show + 1) % 2
    },
    goto,
    bk1(data) {this.form.mjsb.v = data},
    bk2(data) {this.form.boss.v = data},
    bk3(data) {this.form.hc.v = data},
    bk4(data) {this.form.ty.v = data},
    bk5(data) {this.form.zbzj.v = data},
    bk6(data) {this.form.zb.v = data},
    bk7(data) {this.form.dmsb.v = data},
    bk8(data) {this.form.mj.v = data},
    bk9(data) {this.form.dm.v = data},
    doNot() {
      delCookie('risk')
      this.goto('/my/time')
    },
    doOk() {
      console.log(this.form);
      if(riskChk(this.form)) {
        this.okrisk = true
        console.log('ok');
        setCookie('risk', JSON.stringify(this.form))
        this.goto('/my/time')
      }
      else {
        this.okrisk = false
        this.doNot()
      }
      console.log(getCookie('risk'));
    },
    init() {
      let risk = getCookie('risk')
      if(risk) {
        this.okrisk = true
        risk = JSON.parse(risk)
        this.form1 = risk
        this.keys = Object.keys(risk)
        console.log(this.keys, this.form1);
      }
      else this.okrisk = false
    }
  },
  created() {
    this.init()
  }
}
</script>

<style scoped>
  .risk-of {

  }
</style>
